package com.ayuku.course.ui.student;

import java.util.Date;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;

import com.ayuku.commons.AYConst;
import com.ayuku.commons.SqliteDB;
import com.ayuku.commons.Util;
import com.ayuku.commons.ui.ListMasterForm;
import com.ayuku.course.persistence.model.Employee;

public class ListStudent extends ListMasterForm {
	private FormStudent frm;
	private Employee pjo;
	private String name;
	private String password;
	private String level;
	private String phone;
	private String address;
	private String kode;
	private Date joinDate;
	private String email;

	public ListStudent(Composite parent, int style) {
		super(parent, style);

	}

	@Override
	protected String[] getColumCaption() {
		final String[] titles = { "Kode", "Nama", "Alamat", "Phone", "Level",
				"password", "Join Date" };
		return titles;
	}

	@Override
	protected int[] getColumWidth() {
		int[] i = { 80, 200, 250, 100, 100, 100, 100 };
		return i;
	}


	@Override
	public void additionalProcess() {
		System.out.println("... masuk additinal proses ...");
	}

	public static List<Employee> getList(String arg) throws Exception {
		return SqliteDB
				.getPersist()
				.readList(
						Employee.class,
						"SELECT * FROM employee WHERE code LIKE ? or name LIKE ? LIMIT 1000",
						new Object[] { arg, arg });
	}

	@Override
	protected void populateTable(String sqlDml) throws Exception {

		getTableData().removeAll();
		List<Employee> lst = getList(sqlDml);
		getTableData().setItemCount(lst.size());
		setData(new Object[lst.size()][]);

		for (int i = 0; i < lst.size(); i++) {
			Employee pj = lst.get(i);
			getData()[i] = new String[] { Util.nullToString(pj.getCode()),
					Util.nullToString(pj.getName()),
					Util.nullToString(pj.getAddress()),
					Util.nullToString(pj.getPhone()),
					Util.nullToString(pj.getLevel()),
					Util.nullToString(pj.getPassword()),
					Util.dateToString(pj.getJoinDate()) };
		}
	}

	@Override
	protected void fillTable(Object[] obj, TableItem item) {
		item.setText(0, Util.nullToString(obj[0]));
		item.setText(1, Util.nullToString(obj[1]));
		item.setText(2, Util.nullToString(obj[2]));
		item.setText(3, Util.nullToString(obj[3]));
		item.setText(4, Util.nullToString(obj[4]));
		item.setText(5, Util.nullToString(obj[5]));
		item.setText(6, Util.nullToString(obj[6]));
	}

	@Override
	protected Integer doDelete(List<String> id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void showEditForm() {
		TableItem[] selection = getTableData().getSelection();

		if ((selection != null) && (selection.length > 0)) {
			TableItem itm = (TableItem) selection[0];
			frm = new FormStudent(getShell(), SWT.NULL, AYConst.MODE_VIEW);
			frm.setFormKey(itm.getText(0));
			frm.setFuncId(getFuncId());
			//frm.open();
		} else {
		/*	Util.showMsgBox(AYConst.FAIL_VIEW, AYConst.MSG_WARN,
					getDialogShell());*/
		}
	}

	@Override
	public void printPreview() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showAddForm() {
		// TODO Auto-generated method stub
		
	}




}
